﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Data;
namespace DAO
{
    public class KhachHangDAO
    {
        public static List<KhachHangDTO> LayDanhSachKhachHang()
        {
            List<KhachHangDTO> kh = new List<KhachHangDTO>();
            sqlDataAccessHelper connect = new sqlDataAccessHelper();
            try
            {
                DataTable table = new DataTable();
                table = connect.ExecuteQuery("select kh.MaKhachHang, kh.TenKhachHang, kh.CMND, kh.DiaChi, lkh.TenLoaiKhachHang from KHACHHANG kh, LOAIKHACHHANG lkh where kh.MaLoaiKhachHang = lkh.MaLoaiKhachHang");
                for (int i = 0; i < table.Rows.Count; i++ )
                {
                    KhachHangDTO khang = new KhachHangDTO();
                    khang.MaKhachHang = int.Parse(table.Rows[i]["MaKhachHang"].ToString());
                    khang.TenKhachHang = table.Rows[i]["TenKhachHang"].ToString();
                    khang.CMND = int.Parse(table.Rows[i]["CMND"].ToString());
                    khang.DiaChi = table.Rows[i]["DiaChi"].ToString();
                    //khang.MaLoaiKhachHang = table.Rows[i]["TenLoaiKhachHang"].ToString();
                    khang.TenLKH1 = table.Rows[i]["TenLoaiKhachHang"].ToString();
                    kh.Add(khang);
                }
            }
            catch (Exception ex)
            {
 
            }
            return kh;
        }

    }
}
